<?php
namespace common\models;


class smsLog extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'sms_log';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['mobile', 'captcha', 'ip', 'msg', 'create_time'], 'required'],
            [['type', 'member_id'], 'integer'],
            [['create_time'], 'safe'],
            [['mobile', 'res'], 'string', 'max' => 128],
            [['captcha'], 'string', 'max' => 6],
            [['ip'], 'string', 'max' => 15],
            [['msg'], 'string', 'max' => 300],
            [['member_name'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => '记录ID',
            'mobile' => '手机号 或是验证码',
            'captcha' => '短信验证码',
            'ip' => '请求IP',
            'msg' => '短信内容',
            'type' => '短信类型:1为注册,2为登录,3为找回密码,默认为1',
            'res' => '发送结果',
            'create_time' => '添加时间',
            'member_id' => '会员ID,注册为0',
            'member_name' => '会员名',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;

		foreach($extends as $extend)
		{

		}

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

}